package main

import "fmt"

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}
func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func maxArea(height []int) int {
	i, j, areaMax := 0, len(height)-1, 0
	for i < j {
		areaMax = max(min(height[i], height[j])*(j-i), areaMax)
		if height[i] < height[j] {
			i++
		} else {
			j--
		}
	}
	return areaMax
}
func main() {
	fmt.Println(maxArea([]int{1, 8, 6, 2, 5, 4, 8, 3, 7}))
}
